<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人才库管理模块</title>
   <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
   <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
   <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="resources/layer/layer.js"></script>
</head>
<body>
	<div class="jumbotron text-center" style="margin-bottom:0">
		<h3>人才库管理列表</h3>
		<button type="button" class="btn btn-success pull-right" onclick="location='add'">添加人才</button>
		<table class="table table-bordered table-hover">
        <caption>•人才库管理</caption>
	    <thead>
	        <tr>
	        	<th class="text-center">多选</th>
	        	<th class="text-center">编号</th>
	        	<th class="text-center">姓名</th>
	            <th class="text-center">性别</th>
	            <th class="text-center">身份证</th>
	            <th class="text-center">出生日期</th>
	            <th class="text-center">联系电话</th>
	            <th class="text-center">操作</th>
	        </tr>
	    </thead>
	    <tbody>
	    	<c:forEach var="a" items="${list}">
               <tr>
   				  <td><input type="checkbox" name="id[]" value="${a.id}"/></td>
                  <td>${a.id}</td>
                  <td>${a.name}</td>
                  <td>${a.sex=="1"? "男" : "女"}</td>
                  <td>${a.idcard}</td>
                  <td>${a.birth}</td>
                  <td>${a.phone}</td>
                  <td><button type="button" class="btn btn-primary" onclick="location='edit?id=${a.id}'">修改</button>&emsp;<button type="button" class="btn btn-warning" onclick="del(${a.id})">删除</button></td>
                </tr>
             </c:forEach>
	    </tbody>
	</table>
	<button type="button" class="btn btn-warning pull-right" onclick="del()">多选删除</button>
	</div>
</body>
</html>
<script>
/* 批量删除 */
function del(i="i"){
	if(i=="i"){
	      let ids = $('input[name="id[]"]:checked');
	      // 删除的ID
	      let id = []; 
		  // 循环
		  $.each(ids, (key, val) => {
		      // dom对象 转为 jquery对象 $(dom对象)
		      id.push(val.value);
		  });
		  if(id.length > 0){
				layer.confirm("您真的要删除选中的人才信息吗？",{
					btn:['确认删除','思考一下']
				},()=>{
					send(id);
				});
		  }else{
			    layer.msg("请选择要删除的人才信息！",{icon:0,time:1500}) 
		  }
	}else{
		layer.confirm("您真的要删除这条人才信息吗？",{
			btn:['确认删除','思考一下']
		},()=>{
			send([i]);
		});
	}
	
}
// 发送ajax
function send(id){
	// 设置定时器
	let time = setTimeout(()=>{layer.msg("很遗憾，删除人才信息出错",{icon:0,time:1500})}, 2000);
   	// 发起ajax
   	$.ajax({
   		url:"delete",
   		data:{id},
   		type:'POST'
   	}).then(ret=>{
       	// 清除定时器
       	clearTimeout(time);
   		if(ret=="success"){
   			layer.msg("恭喜，删除成功！",{icon:6,time:1500},()=>{
   				location.reload();
   			})
   		}else{
   			layer.msg("很遗憾，删除失败",{icon:5,time:1500},()=>{
   				location.reload();
   			})
   		}
   	});
}
</script>
